package com.ychs.lawyer.controller;

import com.github.pagehelper.PageHelper;
import com.ychs.lawyer.bean.Case;
import com.ychs.lawyer.bean.Lawyer;
import com.ychs.lawyer.bean.R;
import com.ychs.lawyer.service.LawyerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: clh
 * @Date: 2024/07/27/22:30
 * @Description:
 */
@Api(tags = "律师档案管理")
@RestController
@RequestMapping("/lawyer")
public class LawyerController {
    @Autowired
    private LawyerService lawyerService;

    @ApiOperation("查询所有律师信息")
    @GetMapping("/list")
    public R<?> getLawyersByCondition(Lawyer lawyer){
        PageHelper.startPage(lawyer.getPage(),lawyer.getPageSize());
        List<Lawyer> lawyers = lawyerService.getLawyersByCondition(lawyer);
        return R.success(lawyers);
}

    @ApiOperation("添加新律师")
    @PostMapping("/add")
    public R<?> addLawyer(@RequestBody Lawyer lawyer) {
        int res = lawyerService.addLawyer(lawyer);
        return res > 0?R.success():R.fail();
    }

    @ApiOperation("修改律师信息")
    @PostMapping("/edit")
    public R<?> editLawyer(@RequestBody Lawyer lawyer) {
        int res = lawyerService.editLawyer(lawyer);
        return res > 0?R.success():R.fail();
    }

    @ApiOperation("查询指定律师曾代理案件总数")
    @PostMapping("/selectCase")
    public R<?> selectCase(String lawyerName) {
       int total = lawyerService.selectCase(lawyerName);
       return R.success(total);
    }

    @ApiOperation("查询指定律师下曾代理的案件")
    @PostMapping("/selectLawyerName")
    public R<?> selectLawyerName(String lawyerName) {
       List<Case> lawyerCases= lawyerService.selectLawyerName(lawyerName);
       return R.success(lawyerCases);
    }

    @ApiOperation("胜诉个数")
    @PostMapping("/selectVictoryCase")
    public R<?> selevicToase(String lawyerName) {
       int victotal = lawyerService.selectVictoryCase(lawyerName);
       return R.success(victotal);
    }

    @ApiOperation("败诉个数")
    @PostMapping("/selectFaildCase")
    public R<?> selectFaildCase(String lawyerName) {
       int ftotal = lawyerService.selectFaildCase(lawyerName);
       return R.success(ftotal);
    }

    @ApiOperation("调节个数")
    @PostMapping("/selectTalkCase")
    public R<?> selectTalkCase(String lawyerName) {
       int ttotal = lawyerService.selectTalkCase(lawyerName);
       return R.success(ttotal);
    }

}
